﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using ComLib.Web.Modules.Feedbacks;
using ComLib.Web.Lib.Controllers;
using ComLib.Extensions;
using ComLib.CaptchaSupport;
using ComLib.Web.Lib.Models;


namespace ComLib.CMS.Controllers
{
    /// <summary>
    /// Controller for Dynamic Html content pages.
    /// </summary>
    [HandleError]
    public class FeedbackController : EntityControllerAdminBase<Feedback>
    {
        /// <summary>
        /// Override the location for create page to use the local create page.
        /// </summary>
        protected override void Init()
        {
            PageLocationForCreate = "Create";
        }


        [AcceptVerbs(HttpVerbs.Post)]        
        public ActionResult Create(Feedback entity)
        {
            // Wrong verification code.
            if (!Captcha.IsCorrect())
                return BuildViewModelFormWithErrors(entity, PageLocationForCreate, "Verification code is incorrect");
            
            // Some other form / entity errors.
            if (!entity.Validate())
                return BuildViewModelFormWithErrors(entity, PageLocationForCreate, null);

            return CreateThankYou(entity, "Thank you for submitting your feedback");            
        }
    }
}
